package com.gengdan.controller;

import com.gengdan.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/login")
@Controller
public class UserLoginController {

    @Autowired
    private UserLoginService userLoginService;

    /**
     * 登录模块中的登陆功能
     * @param map 需要登录的用户名
     * @return 带有指定用户数据的结果集（自动转json）
     */
    @RequestMapping("/sign_in")
    @ResponseBody
    public HashMap login(@RequestBody Map map){

        String loginName = "";

        if(map.containsKey("login_name")){
            loginName = map.get("login_name").toString();
        }

        return  userLoginService.getUserLoginByLoginName(loginName);
    }

    /**
     * 登录模块中的邮箱发送密码重置链接功能
     * @return 邮箱发送情况
     */

    @RequestMapping("/find_password")
    @ResponseBody
    public HashMap sendEmail(@RequestParam("login_name")String loginName){

        return userLoginService.reportEmailStatus(loginName) ;

    }

    @RequestMapping("/to_reset")
    @ResponseBody
    public HashMap resetPassword(@RequestParam("login_name")String loginName,
                                 @RequestParam("token")String token){

        return userLoginService.reportResetStatus(loginName,token);
    }



}
